package com.boful.convert.core;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.Node;

public class HostConfig {
	private String ip;
	private int port;
	private String name;
	private Map<String, String> params = new HashMap<String, String>();

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public Map<String, String> getParams() {
		return params;
	}

	public void setParams(Map<String, String> params) {
		this.params = params;
	}

	@SuppressWarnings("unchecked")
	public void init(Element node) {

		Element ipNode = node.element("ip");
		Element portNode = node.element("port");
		Element params = node.element("params");

		
		setIp(ipNode.getText());
		setPort(Integer.parseInt(portNode.getText()));
		setName(node.attributeValue("name"));

		List<Element> paramsElements = params.elements("param");
		for (Element element : paramsElements) {
			String elementName = element.attributeValue("name");
			String elementValue = element.getText();
			getParams().put(elementName, elementValue);
		}

	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

}
